/**
 * 
 */
package com.byzk.p2p.admin.borrow.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.byzk.p2p.admin.base.controller.BaseController;
import com.byzk.p2p.admin.base.util.BaseUtil;
import com.byzk.p2p.admin.base.util.JsonMsg;
import com.byzk.p2p.admin.borrow.dao.TenderDao;
import com.byzk.p2p.admin.borrow.dto.Borrow;
import com.byzk.p2p.admin.borrow.service.BorrowService;
import com.byzk.p2p.admin.borrow.service.CancelService;
import com.byzk.p2p.admin.borrow.service.ProductService;
import com.byzk.p2p.admin.borrow.service.TenderService;
import com.byzk.p2p.admin.borrow.vo.UserTenderVo;
import com.byzk.p2p.admin.fuiou.controller.FuionAccountController;
import com.byzk.p2p.admin.fuiou.service.PreAuthCancelService;
import com.byzk.p2p.admin.money.dao.FundRecordDao;
import com.byzk.p2p.admin.money.dto.FundRecord;
import com.byzk.p2p.admin.money.util.FundRecordType;
import com.byzk.p2p.admin.order.service.OrderService;
import com.byzk.p2p.admin.user.dao.UserAccountDao;
import com.byzk.p2p.admin.user.dto.User;
import com.byzk.p2p.admin.user.dto.UserAccount;
import com.byzk.p2p.admin.user.service.UserAccountService;
import com.byzk.p2p.admin.user.service.UserAuthService;
import com.byzk.p2p.admin.user.service.UserService;

/**
 * @Description:TODO
 * @author:Administrator
 * @time:2017年4月5日 上午8:41:14
 */
@Controller
@RequestMapping(value = "/borrow")
public class CancelController extends BaseController {

	@Autowired
	private UserService userService;
	@Autowired
	private TenderService tenderService;
	@Autowired
	private CancelService cancelService;
	@Autowired
	private PreAuthCancelService  preAuthCancelService;
	/**
	 * Description:流标 Company:xbd
	 * 
	 * @author:lilei
	 * @throws Exception
	 * @date:2017年4月5日上午8:45:38
	 */
	@RequestMapping(value = "/cancel/mark", method = RequestMethod.POST)
	public void CancelMark(@RequestParam(value = "borrowId", required = true) Integer borrowId) throws Exception {

		try {
			Integer count = 0;
			List<UserTenderVo> tenderList = cancelService.listUserTenderByBorrowId(borrowId);
			if (tenderList != null && tenderList.size() > 0) {
				for (UserTenderVo vo : tenderList) {
					if (preAuthCancelService.preAuthCancel(borrowId, vo)) {
						count++;
					}
				}
			}
			if (count == tenderList.size()) {
				super.printJSON(new JsonMsg(-1, "流标成功"));
			} else {
				super.printJSON(new JsonMsg(2, "流标失败"));
			}
		} catch (Exception e) {
			super.printJSON(new JsonMsg(1, e.getMessage()));
		}

	}

}
